<template>
  <view class="flex-col">
    <!--申请信息 -->
    <newApplication v-model="ruleForm" title="车辆信息" :boole="boole" ref="refNewApplication" />

    <!--审批流程-->
    <exam-flow v-if="flowId" :instanceId="flowId" />

    <view class="button-container" v-if="boole">
      <button class="btn-item" @click="submit">提 交</button>
    </view>
  </view>
</template>

<script>
import * as apis from '@/api/vehicleWarning'
import newApplication from '../routineApplyFor/components/newApplication.vue'

export default {
  name: 'add',
  components: { newApplication },
  computed: {},
  watch: {},
  onLoad(op) {
    let title = ''
    this.flowId = op?.flowId
    if (op?.type === 'edit') {
      title = '处置车辆'
      this.boole = true
    }
    if (op?.type === 'view') {
      title = '处置车辆详情'
      this.boole = false
    }
    uni.setNavigationBarTitle({
      title,
    })
    op?.id && this.handleCarIdData(op?.id)
  },
  data() {
    return {
      ruleForm: {
        carId: null,
        carNo: '',
        vinNo: '',
        brandId: '',
        seriesId: '',
        modelId: '',
        brandName: '',
        modelName: '',
        seriesName: '',
        propertyRightId: '',
        propertyRightName: '',
        registerTime: '',
        carAge: '',
        environmentalStandards: '',
        licenseNature: '',
        fuelType: '',
        liter: '',
        seatNum: '',
        gearPosition: '',
        exteriorColor: '',
        carType: '',
        accidentAmountThreeYears: '',
        guidancePrice: '',
        purchasePrice: '',
        initialResidualValue: '',
        mileage: '',
        transferCount: '',
        vehicleConditionLevel: '',
        cityName: '',
        disposalReason: '',
        vehicleStatus: '',
        attachment: ''
      },
      boole: false,
      flowId: null,
    }
  },
  methods: {
    //carId   查询接口
    async handleCarIdData(id) {
      try {
        let res = await apis?.getVehicleDisposal(id)
        console.log(res.data)
        if (res.data) {
          this.ruleForm = { ...res.data }
        }
      } catch (e) {
        console.error(e)
      }
    },
    async submit() {
      try {
        uni.showLoading()
        await this.$refs.refNewApplication.handleEffect()
        const res = await apis?.vehicleDisposal(this.ruleForm)
        if (res.code === 200) {
          this.$modal.msgSuccess('提交成功')
          setTimeout(() => {
            this.$tab.navigateTo('/pages/VehiclePage/vehicleWarning/list')
          }, 1000)
        }
      } catch (error) {
        this.$nextTick(() => {
          uni.pageScrollTo({
            selector: error,
          })
        })
      } finally {
        uni.hideLoading()
      }
    },
  },
}
</script>

<style scoped lang=""></style>
